import 'package:date_format/date_format.dart';
import 'package:flutter_ncsjqz_getx/http/dio_service.dart';
import 'package:flutter_ncsjqz_getx/model/base_entity.dart';
import 'package:flutter_ncsjqz_getx/model/isolation_range_entity.dart';
import 'package:flutter_ncsjqz_getx/util/toast_util.dart';
import 'package:get/get.dart';

class IsolateLogic extends GetxController {
  bool showSetting = false;
  DateTime? startDate = DateTime.now();
  DateTime? endDate = DateTime.now();
  List blockUserIds=[];
  List ryUserIds=[];
  String glName  = "";
  setShowSetting(val){
    showSetting = val;
    update();
  }

  setStartDate(value){
    startDate = value;
    update();
  }

  setEndDate(value){
    endDate = value;
    update();
  }

  /// todo：获取隔离信息
  getData() async{
    IsolationRangeEntity baseEntity = await DioService<IsolationRangeEntity>().queryIsolationInfo();
    if(baseEntity.code == 0 && baseEntity.data !=null) {
      setShowSetting(baseEntity.data!.isBlock);
      baseEntity.data!.users!.forEach((element) => glName+=element+'、');
      update();
    }
  }

  /// todo：设置隔离信息
  setData() async{
    if(startDate == endDate)return toast("开始时间和结束时间 不可相同");
    Map<String, dynamic> map =new Map();
    map['blockType']=3;
    map['endBlockTime']= formatDate(startDate!,[yyyy, '-', mm, '-', dd,' ',HH, ':', nn, ':', ss]);
    map['isBlock']=showSetting;
    map['startBlockTime']= formatDate(endDate!,[yyyy, '-', mm, '-', dd,' ',HH, ':', nn, ':', ss]);
    map['blockUserIds']=blockUserIds;
    map['ryUserIds']=ryUserIds;
    BaseEntity baseEntity = await DioService<BaseEntity>().setBlacklist(map);
    if(baseEntity.code == 0) {
      toast("设置成功");
    }
  }
}
